package com.py.custom.tms.application.jvm.memory;

import com.py.custom.tms.application.jvm.classload.MyTest16;
import org.springframework.cglib.proxy.Enhancer;

import java.util.ArrayList;

/**
 * description：
 *
 * @author pengyou
 * @version 1.0.0
 * @date 2022/2/26
 */

public class MyTest1 {

    static int[] a = new int[1024 * 1024];
    static int[] b1 = new int[1024 * 500];
//    static int[] b2 = new int[1024 * 100];
    static int[] b2 = new int[1024 * 15];

    public static void main(String[] args) throws Exception {
        // -XX:MetaspaceSize=10M -XX:MaxMetaspaceSize=10M
        // -XX:+HeapDumpOnOutOfMemoryError
        // -Xmx10M -Xmn=10M
        // kb == 1024 b--> 4k*1024


        Enhancer enhancer1 = new Enhancer();
        System.out.println(Runtime.getRuntime().freeMemory());
//        for (int i = 0; i < 478; i++) {
//            enhancer1.setSuperclass(MyTest1.class);
//            enhancer1.setUseCache(false);
//            enhancer1.setCallback(((MethodInterceptor) (obj, method, args1, proxy) -> proxy.invokeSuper(obj, args1)));
//            Object o1 = enhancer1.create();
//
//            Class<?> aClass = o1.getClass();
//            o1 = null;
//            System.out.println("he-" + i + "--" + aClass);
//        }
        System.out.println(Runtime.getRuntime().freeMemory() / 1024 / 1024);
        ArrayList<MyTest16> objects = new ArrayList<>();
        for (int i = 0; i < 2000; i++) {
            MyTest16 loader1 = new MyTest16("loader1");
            objects.add(loader1);
        }
        System.out.println("------------------");
        for (MyTest16 loader1 : objects) {
            loader1.setPath("C:\\Users\\Administrator.DESKTOP-L4OVBNE\\Desktop\\");
            Class<?> clazz3 = loader1.loadClass("com.py.custom.tms.application.jvm.classload.MyTest1");
            System.out.println(clazz3);
            Thread.sleep(1);
        }
        System.out.println(Runtime.getRuntime().freeMemory());
        System.gc();
        System.out.println(enhancer1);
        System.out.println(objects);
    }
}
